package com.edu.common.utils;

import org.shredzone.commons.suncalc.SunTimes;

import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

public class DayNightUtil {

    public static void main(String[] args) {

        ZoneId zoneId= ZoneId.systemDefault();//获取当前计算机默认的时区，也就是东八区时间
        ZonedDateTime now = ZonedDateTime.now(zoneId);
        SunTimes beijing = SunTimes.compute()
                .on(now.getYear(),now.getMonthValue(),now.getDayOfMonth())
                .at(39.94358d, 116.421393d)
                .execute();
        ZonedDateTime rise = beijing.getRise();
        ZonedDateTime set = beijing.getSet();

        System.err.println(rise);
        System.err.println(now);
        System.err.println(set);
        System.err.println(now.isAfter(rise));
        System.err.println(now.isBefore(set));
    }

    // 判断当前时间是否在日出和日落之间
    public static boolean isDaytime(ZonedDateTime time, double latitude, double longitude) {
        SunTimes beijing = SunTimes.compute()
                .on(time.getYear(),time.getMonthValue(),time.getDayOfMonth())
                .at(39.94358d, 116.421393d)
                .execute();
        ZonedDateTime rise = beijing.getRise();
        ZonedDateTime set = beijing.getSet();

        return time.isAfter(rise) && time.isBefore(set);
    }


}
